<!DOCTYPE html>
<html lang=zh>
<head>
    <meta charset="utf-8">
    
    <title>第四十章：基于SpringBoot &amp; Quartz完成定时任务分布式多节点负载持久化 | 恒宇少年De成长之路</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="在上一章【第三十九章：基于SpringBoot &amp;amp; Quartz完成定时任务分布式单节点持久化】中我们已经完成了任务的持久化，当我们创建一个任务时任务会被quartz定时任务框架自动持久化到数据库，我们采用的是SpringBoot项目托管的dataSource来完成的数据源提供，当然也可以使用quartz内部配置数据源方式，我们的标题既然是提到了定时任务的分布式多节点，那么怎么才算是多节点">
<meta name="keywords" content="SpringBoot">
<meta property="og:type" content="article">
<meta property="og:title" content="第四十章：基于SpringBoot &amp; Quartz完成定时任务分布式多节点负载持久化">
<meta property="og:url" content="http://blog.yuqiyu.com/spring-boot-chapter-40/index.html">
<meta property="og:site_name" content="恒宇少年De成长之路">
<meta property="og:description" content="在上一章【第三十九章：基于SpringBoot &amp;amp; Quartz完成定时任务分布式单节点持久化】中我们已经完成了任务的持久化，当我们创建一个任务时任务会被quartz定时任务框架自动持久化到数据库，我们采用的是SpringBoot项目托管的dataSource来完成的数据源提供，当然也可以使用quartz内部配置数据源方式，我们的标题既然是提到了定时任务的分布式多节点，那么怎么才算是多节点">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/4461954-d80b777ca38632ba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2018-01-23T15:50:10.272Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="第四十章：基于SpringBoot &amp; Quartz完成定时任务分布式多节点负载持久化">
<meta name="twitter:description" content="在上一章【第三十九章：基于SpringBoot &amp;amp; Quartz完成定时任务分布式单节点持久化】中我们已经完成了任务的持久化，当我们创建一个任务时任务会被quartz定时任务框架自动持久化到数据库，我们采用的是SpringBoot项目托管的dataSource来完成的数据源提供，当然也可以使用quartz内部配置数据源方式，我们的标题既然是提到了定时任务的分布式多节点，那么怎么才算是多节点">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/4461954-d80b777ca38632ba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
    

    
        <link rel="alternate" href="/" title="恒宇少年De成长之路" type="application/atom+xml" />
    

    

    <link rel="stylesheet" href="/libs/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/libs/open-sans/styles.css">
    <link rel="stylesheet" href="/libs/source-code-pro/styles.css">

    <link rel="stylesheet" href="/css/style.css">

    <script src="/libs/jquery/2.1.3/jquery.min.js"></script>
    
    
        <link rel="stylesheet" href="/libs/lightgallery/css/lightgallery.min.css">
    
    
        <link rel="stylesheet" href="/libs/justified-gallery/justifiedGallery.min.css">
    
    
    
    


</head>

<body>
    <div id="container">
        <header id="header">
    <div id="header-main" class="header-inner">
        <div class="outer">
            <a href="/" id="logo">
                <i class="logo"></i>
                <span class="site-title">恒宇少年De成长之路</span>
            </a>
            <nav id="main-nav">
                
                    <a class="main-nav-link" href="/.">首页</a>
                
                    <a class="main-nav-link" href="/archives">时间轴</a>
                
                    <a class="main-nav-link" href="/categories">文章专题</a>
                
                    <a class="main-nav-link" href="/tags">标签云</a>
                
                    <a class="main-nav-link" href="/about">关于我</a>
                
            </nav>
            
                
                <nav id="sub-nav">
                    <div class="profile" id="profile-nav">
                        <a id="profile-anchor" href="javascript:;">
                            <img class="avatar" src="/css/images/avatar.png" />
                            <i class="fa fa-caret-down"></i>
                        </a>
                    </div>
                </nav>
            
            <div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
        <!--button type="submit" class="search-form-submit"></button-->
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="想要查找什么..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>

</div>
        </div>
    </div>
    <div id="main-nav-mobile" class="header-sub header-inner">
        <table class="menu outer">
            <tr>
                
                    <td ><a  class="main-nav-link" href="/.">首页</a></td>
                
                    <td ><a  class="main-nav-link" href="/archives">时间轴</a></td>
                
                    <td ><a  class="main-nav-link" href="/categories">文章专题</a></td>
                
                    <td ><a  class="main-nav-link" href="/tags">标签云</a></td>
                
                    <td ><a  class="main-nav-link" href="/about">关于我</a></td>
                
                <td>
                    
    <div class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="搜索" />
    </div>

                </td>
            </tr>
        </table>
    </div>
</header>

        <div class="outer">
            
                

<aside id="profile">
    <div class="inner profile-inner">
        <div class="base-info profile-block">
            <img id="avatar" src="/css/images/avatar.png" />
            <h2 id="name">恒宇少年</h2>
            <h3 id="title">Java软件工程师 &amp; 程序猿</h3>
            <span id="location"><i class="fa fa-map-marker"></i>山东, 济南</span>
            <a id="follow" target="_blank" href="https://www.jianshu.com/u/092df3f77bca">关注我</a>
        </div>
        <div class="article-info profile-block">
            <div class="article-info-block">
                43
                <span>文章</span>
            </div>
            <div class="article-info-block">
                2
                <span>标签</span>
            </div>
        </div>
        
        <div class="profile-block social-links">
            <table>
                <tr>
                    
                    
                    <td>
                        <a href="http://github.com/ppoffice/hexo-theme-icarus" target="_blank" title="github" class=tooltip>
                            <i class="fa fa-github"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="twitter" class=tooltip>
                            <i class="fa fa-twitter"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="facebook" class=tooltip>
                            <i class="fa fa-facebook"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="dribbble" class=tooltip>
                            <i class="fa fa-dribbble"></i>
                        </a>
                    </td>
                    
                    <td>
                        <a href="/" target="_blank" title="rss" class=tooltip>
                            <i class="fa fa-rss"></i>
                        </a>
                    </td>
                    
                </tr>
            </table>
        </div>
        
    </div>
</aside>

            
            <section id="main"><article id="post-spring-boot-chapter-40" class="article article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
        
        
            <header class="article-header">
                
    
        <h1 class="article-title" itemprop="name">
            第四十章：基于SpringBoot &amp; Quartz完成定时任务分布式多节点负载持久化
        </h1>
    

                
                    <div class="article-meta">
                        
    <div class="article-date">
        <i class="fa fa-calendar"></i>
        <a href="/spring-boot-chapter-40/">
            <time datetime="2017-11-11T16:00:00.000Z" itemprop="datePublished">2017-11-12</time>
        </a>
    </div>


                        
    <div class="article-category">
    	<i class="fa fa-folder"></i>
        <a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a>
    </div>

                        
    <div class="article-tag">
        <i class="fa fa-tag"></i>
        <a class="tag-link" href="/tags/SpringBoot/">SpringBoot</a>
    </div>

                    </div>
                
            </header>
        
        
        <div class="article-entry" itemprop="articleBody">
        
            
            <p>在上一章【<a href="http://www.jianshu.com/p/d52d62fb2ac6" target="_blank" rel="noopener">第三十九章：基于SpringBoot &amp; Quartz完成定时任务分布式单节点持久化</a>】中我们已经完成了任务的持久化，当我们创建一个任务时任务会被<code>quartz</code>定时任务框架自动持久化到数据库，我们采用的是<code>SpringBoot</code>项目托管的<code>dataSource</code>来完成的数据源提供，当然也可以使用<code>quartz</code>内部配置数据源方式，我们的标题既然是提到了定时任务的分布式多节点，那么怎么才算是多节点呢？当有节点故障或者手动停止运行后是否可以自动漂移任务到可用的分布式节点呢？<br><a id="more"></a></p>
<h1 id="本章目标"><a href="#本章目标" class="headerlink" title="本章目标"></a>本章目标</h1><blockquote>
<ol>
<li>完成定时任务分布式多节点配置，当单个节点关闭时其他节点自动接管定时任务。</li>
<li>创建任务时传递自定义参数，方便任务处理后续业务逻辑。</li>
</ol>
</blockquote>
<h1 id="SpringBoot-企业级核心技术学习专题"><a href="#SpringBoot-企业级核心技术学习专题" class="headerlink" title="SpringBoot 企业级核心技术学习专题"></a>SpringBoot 企业级核心技术学习专题</h1><table>
<thead>
<tr>
<th style="text-align:center">专题</th>
<th style="text-align:left">专题名称</th>
<th style="text-align:left">专题描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">001</td>
<td style="text-align:left"><a href="http://www.jianshu.com/c/3f69deddbed3" target="_blank" rel="noopener">Spring Boot 核心技术</a></td>
<td style="text-align:left">讲解SpringBoot一些企业级层面的核心组件</td>
</tr>
<tr>
<td style="text-align:center">002</td>
<td style="text-align:left"><a href="https://gitee.com/hengboy/spring-boot-chapter" target="_blank" rel="noopener">Spring Boot 核心技术章节源码</a></td>
<td style="text-align:left">Spring Boot 核心技术简书每一篇文章码云对应源码</td>
</tr>
<tr>
<td style="text-align:center">003</td>
<td style="text-align:left"><a href="http://www.jianshu.com/c/1faac22666e7" target="_blank" rel="noopener">Spring Cloud 核心技术</a></td>
<td style="text-align:left">对Spring Cloud核心技术全面讲解</td>
</tr>
<tr>
<td style="text-align:center">004</td>
<td style="text-align:left"><a href="https://gitee.com/hengboy/spring-cloud-chapter" target="_blank" rel="noopener">Spring Cloud 核心技术章节源码</a></td>
<td style="text-align:left">Spring Cloud 核心技术简书每一篇文章对应源码</td>
</tr>
<tr>
<td style="text-align:center">005</td>
<td style="text-align:left"><a href="http://www.jianshu.com/c/ab4789177827" target="_blank" rel="noopener">QueryDSL 核心技术</a></td>
<td style="text-align:left">全面讲解QueryDSL核心技术以及基于SpringBoot整合SpringDataJPA</td>
</tr>
<tr>
<td style="text-align:center">006</td>
<td style="text-align:left"><a href="http://www.jianshu.com/c/f1b269bb2fd6" target="_blank" rel="noopener">SpringDataJPA 核心技术</a></td>
<td style="text-align:left">全面讲解SpringDataJPA核心技术</td>
</tr>
</tbody>
</table>
<h1 id="构建项目"><a href="#构建项目" class="headerlink" title="构建项目"></a>构建项目</h1><blockquote>
<p>注意：我们本章项目需要结合上一章共同完成，有一点要注意的是任务在持久化到数据库内时会保存任务的全路径，如：<code>com.hengyu.chapter39.timers.GoodStockCheckTimer</code> ，<code>quartz</code>在运行任务时会根据任务全路径去执行，如果不一致则会提示找不到指定类，我们本章在创建项目时<code>package</code>需要跟上一章完全一致。</p>
</blockquote>
<p>我们这里就不去直接创建新项目了，直接复制上一章项目的源码为新的项目命名为<code>Chapter40</code></p>
<h3 id="配置分布式"><a href="#配置分布式" class="headerlink" title="配置分布式"></a>配置分布式</h3><p>在上一章配置文件<code>quartz.properties</code>中我们其实已经为分布式做好了相关配置，下面我们就来看一下分布式相关的配置。<br>分布式相关配置：</p>
<p><code>1. org.quartz.scheduler.instanceId</code> ： 定时任务的实例编号，如果手动指定需要保证每个节点的唯一性，因为<code>quartz</code>不允许出现两个相同<code>instanceId</code>的节点，我们这里指定为<code>Auto</code>就可以了，我们把生成编号的任务交给<code>quartz</code>。</p>
<p><code>2. org.quartz.jobStore.isClustered</code>： 这个属性才是真正的开启了定时任务的分布式配置，当我们配置为<code>true</code>时<code>quartz</code>框架就会调用<code>ClusterManager</code>来初始化分布式节点。</p>
<p><code>3. org.quartz.jobStore.clusterCheckinInterval</code>：配置了分布式节点的检查时间间隔，单位：毫秒。<br>下面是<code>quartz.properties</code>配置文件配置信息：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">#调度器实例名称</span><br><span class="line">org.quartz.scheduler.instanceName = quartzScheduler</span><br><span class="line"></span><br><span class="line">#调度器实例编号自动生成</span><br><span class="line">org.quartz.scheduler.instanceId = AUTO</span><br><span class="line"></span><br><span class="line">#持久化方式配置</span><br><span class="line">org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX</span><br><span class="line"></span><br><span class="line">#持久化方式配置数据驱动，MySQL数据库</span><br><span class="line">org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate</span><br><span class="line"></span><br><span class="line">#quartz相关数据表前缀名</span><br><span class="line">org.quartz.jobStore.tablePrefix = QRTZ_</span><br><span class="line"></span><br><span class="line">#开启分布式部署</span><br><span class="line">org.quartz.jobStore.isClustered = true</span><br><span class="line">#配置是否使用</span><br><span class="line">org.quartz.jobStore.useProperties = false</span><br><span class="line"></span><br><span class="line">#分布式节点有效性检查时间间隔，单位：毫秒</span><br><span class="line">org.quartz.jobStore.clusterCheckinInterval = 10000</span><br><span class="line"></span><br><span class="line">#线程池实现类</span><br><span class="line">org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool</span><br><span class="line"></span><br><span class="line">#执行最大并发线程数量</span><br><span class="line">org.quartz.threadPool.threadCount = 10</span><br><span class="line"></span><br><span class="line">#线程优先级</span><br><span class="line">org.quartz.threadPool.threadPriority = 5</span><br><span class="line"></span><br><span class="line">#配置为守护线程，设置后任务将不会执行</span><br><span class="line">#org.quartz.threadPool.makeThreadsDaemons=true</span><br><span class="line"></span><br><span class="line">#配置是否启动自动加载数据库内的定时任务，默认true</span><br><span class="line">org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true</span><br></pre></td></tr></table></figure></p>
<p>当我们启动任务节点时，会根据<code>org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread</code>属性配置进行是否自动加载任务，默认<code>true</code>自动加载数据库内的任务到节点。</p>
<p>###测试分布式</p>
<p>上一章项目节点名称：<code>quartz-cluster-node-first</code><br>本章项目节点名称：<code>quartz-cluster-node-second</code></p>
<p>由于我们<code>quartz-cluster-node-first</code>的商品库存检查定时任务是每隔30秒执行一次，所以任务除非手动清除否则是不会被清空的，在运行项目测试之前需要将<code>application.yml</code>配置文件的端口号、项目名称修改下，保证<code>quartz-cluster-node-second</code>与<code>quartz-cluster-node-first</code>端口号不一致，可以同时运行，修改后为：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">spring:</span><br><span class="line">    application:</span><br><span class="line">        name: quzrtz-cluster-node-second</span><br><span class="line">server:</span><br><span class="line">  port: 8082</span><br></pre></td></tr></table></figure></p>
<p>然后修改相应控制台输出，为了能够区分任务执行者是具体的节点。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Chapter40Application启动类修改日志输出：</span><br><span class="line">logger.info(&quot;【【【【【【定时任务分布式节点 - quartz-cluster-node-second 已启动】】】】】】&quot;);</span><br><span class="line"></span><br><span class="line">GoodAddTimer商品添加任务类修改日志输出：</span><br><span class="line">logger.info(&quot;分布式节点quartz-cluster-node-second，商品添加完成后执行任务，任务时间：&#123;&#125;&quot;,new Date());</span><br><span class="line"></span><br><span class="line">GoodStockCheckTimer商品库存检查任务类修改日志输出：</span><br><span class="line">logger.info(&quot;分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：&#123;&#125;&quot;,new Date());</span><br></pre></td></tr></table></figure>
<p>下面我们启动本章项目，查看控制台输出内容，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">2017-11-12 10:28:39.969  INFO 11048 --- [           main] c.hengyu.chapter39.Chapter40Application  : 【【【【【【定时任务分布式节点 - quartz-cluster-node-second 已启动】】】】】】</span><br><span class="line">2017-11-12 10:28:41.930  INFO 11048 --- [lerFactoryBean]] o.s.s.quartz.SchedulerFactoryBean        : Starting Quartz Scheduler now, after delay of 2 seconds</span><br><span class="line">2017-11-12 10:28:41.959  INFO 11048 --- [lerFactoryBean]] org.quartz.core.QuartzScheduler          : Scheduler schedulerFactoryBean_$_yuqiyu1510453719308 started.</span><br><span class="line">2017-11-12 10:28:51.963  INFO 11048 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore     : ClusterManager: detected 1 failed or restarted instances.</span><br><span class="line">2017-11-12 10:28:51.963  INFO 11048 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore     : ClusterManager: Scanning for instance &quot;yuqiyu1510450938654&quot;&apos;s failed in-progress jobs.</span><br><span class="line">2017-11-12 10:28:51.967  INFO 11048 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore     : ClusterManager: ......Freed 1 acquired trigger(s).</span><br><span class="line">2017-11-12 10:29:00.024  INFO 11048 --- [ryBean_Worker-1] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 10:29:00 CST 2017</span><br></pre></td></tr></table></figure></p>
<p>可以看到项目启动完成后自动分配的<code>instanceId</code>为<code>yuqiyu1510450938654</code>，生成的规则是当前用户的名称+时间戳。然后<code>ClusterManager</code>分布式管理者自动介入进行扫描是否存在匹配的触发器任务，如果存在则会自动执行任务逻辑，而商品库存检查定时任务确实由<code>quartz-cluster-node-second</code>进行输出的。</p>
<p>###测试任务自动漂移<br>下面我们也需要把<code>quartz-cluster-node-first</code>的输出进行修改，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">Chapter39Application启动类修改日志输出：</span><br><span class="line">logger.info(&quot;【【【【【【定时任务分布式节点 - quartz-cluster-node-first 已启动】】】】】】&quot;);</span><br><span class="line"></span><br><span class="line">GoodAddTimer商品添加任务类修改日志输出：</span><br><span class="line">logger.info(&quot;分布式节点quartz-cluster-node-first，商品添加完成后执行任务，任务时间：&#123;&#125;&quot;,new Date());</span><br><span class="line"></span><br><span class="line">GoodStockCheckTimer商品库存检查任务类修改日志输出：</span><br><span class="line">logger.info(&quot;分布式节点quartz-cluster-node-first，执行库存检查定时任务，执行时间：&#123;&#125;&quot;,new Date());</span><br></pre></td></tr></table></figure></p>
<p>接下来我们启动<code>quartz-cluster-node-first</code>，并查看控制台的输出内容：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">2017-11-12 10:34:09.750  INFO 192 --- [           main] c.hengyu.chapter39.Chapter39Application  : 【【【【【【定时任务分布式节点 - quartz-cluster-node-first 已启动】】】】】】</span><br><span class="line">2017-11-12 10:34:11.690  INFO 192 --- [lerFactoryBean]] o.s.s.quartz.SchedulerFactoryBean        : Starting Quartz Scheduler now, after delay of 2 seconds</span><br><span class="line">2017-11-12 10:34:11.714  INFO 192 --- [lerFactoryBean]] org.quartz.core.QuartzScheduler          : Scheduler schedulerFactoryBean_$_yuqiyu1510454049066 started.</span><br></pre></td></tr></table></figure></p>
<p>项目启动完成后，定时节点并没有实例化<code>ClusterManager</code>来完成分布式节点的初始化，因为<code>quartz</code>检测到有其他的节点正在处理任务，这样也是保证了任务执行的唯一性。</p>
<p>####关闭quartz-cluster-node-second<br>我们关闭<code>quartz-cluster-node-second</code>运行的项目，预计的目的可以达到<code>quartz-cluster-node-first</code>会自动接管数据库内的任务，完成任务执行的自动漂移，我们来查看<code>quartz-cluster-node-first</code>的控制台输出内容：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">2017-11-12 10:34:09.750  INFO 192 --- [           main] c.hengyu.chapter39.Chapter39Application  : 【【【【【【定时任务分布式节点 - quartz-cluster-node-first 已启动】】】】】】</span><br><span class="line">2017-11-12 10:34:11.690  INFO 192 --- [lerFactoryBean]] o.s.s.quartz.SchedulerFactoryBean        : Starting Quartz Scheduler now, after delay of 2 seconds</span><br><span class="line">2017-11-12 10:34:11.714  INFO 192 --- [lerFactoryBean]] org.quartz.core.QuartzScheduler          : Scheduler schedulerFactoryBean_$_yuqiyu1510454049066 started.</span><br><span class="line">2017-11-12 10:41:11.793  INFO 192 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore     : ClusterManager: detected 1 failed or restarted instances.</span><br><span class="line">2017-11-12 10:41:11.793  INFO 192 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore     : ClusterManager: Scanning for instance &quot;yuqiyu1510453719308&quot;&apos;s failed in-progress jobs.</span><br><span class="line">2017-11-12 10:41:11.797  INFO 192 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore     : ClusterManager: ......Freed 1 acquired trigger(s).</span><br><span class="line">2017-11-12 10:41:11.834  INFO 192 --- [ryBean_Worker-1] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-first，执行库存检查定时任务，执行时间：Sun Nov 12 10:41:11 CST 2017</span><br></pre></td></tr></table></figure></p>
<p>控制台已经输出了持久的定时任务，输出节点是<code>quartz-cluster-node-first</code>，跟我们预计的一样，节点<code>quartz-cluster-node-first</code>完成了自动接管<code>quartz-cluster-node-second</code>的工作，而这个过程肯定有一段时间间隔，而这个间隔可以修改<code>quartz.properties</code>配置文件内的属性<code>org.quartz.jobStore.clusterCheckinInterval</code>进行调节。</p>
<p>####关闭quartz-cluster-node-first<br>我们同样可以测试启动任务节点<code>quartz-cluster-node-second</code>后，再关闭<code>quartz-cluster-node-first</code>任务节点，查看<code>quartz-cluster-node-second</code>控制台的输出内容：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">2017-11-12 10:53:31.010  INFO 3268 --- [           main] c.hengyu.chapter39.Chapter40Application  : 【【【【【【定时任务分布式节点 - quartz-cluster-node-second 已启动】】】】】】</span><br><span class="line">2017-11-12 10:53:32.967  INFO 3268 --- [lerFactoryBean]] o.s.s.quartz.SchedulerFactoryBean        : Starting Quartz Scheduler now, after delay of 2 seconds</span><br><span class="line">2017-11-12 10:53:32.992  INFO 3268 --- [lerFactoryBean]] org.quartz.core.QuartzScheduler          : Scheduler schedulerFactoryBean_$_yuqiyu1510455210493 started.</span><br><span class="line">2017-11-12 10:53:52.999  INFO 3268 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore     : ClusterManager: detected 1 failed or restarted instances.</span><br><span class="line">2017-11-12 10:53:52.999  INFO 3268 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore     : ClusterManager: Scanning for instance &quot;yuqiyu1510454049066&quot;&apos;s failed in-progress jobs.</span><br><span class="line">2017-11-12 10:53:53.003  INFO 3268 --- [_ClusterManager] o.s.s.quartz.LocalDataSourceJobStore     : ClusterManager: ......Freed 1 acquired trigger(s).</span><br><span class="line">2017-11-12 10:54:00.020  INFO 3268 --- [ryBean_Worker-1] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 10:54:00 CST 2017</span><br></pre></td></tr></table></figure></p>
<p>得到的结果是同样可以完成任务的自动漂移。</p>
<blockquote>
<p>如果两个节点同时启动，哪个节点先把节点信息注册到数据库就获得了优先执行权。</p>
</blockquote>
<h3 id="传递参数到任务"><a href="#传递参数到任务" class="headerlink" title="传递参数到任务"></a>传递参数到任务</h3><p>我们平时在使用任务时，如果是针对性比较强的业务逻辑，肯定需要特定的参数来完成业务逻辑的实现。</p>
<p>下面我们来模拟商品秒杀的场景，当我们添加商品后自动添加一个商品提前五分钟的秒杀提醒，为关注该商品的用户发送提醒消息。<br>我们在节点<code>quartz-cluster-node-first</code>中添加秒杀提醒任务，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">package com.hengyu.chapter39.timers;</span><br><span class="line"></span><br><span class="line">import org.quartz.JobDataMap;</span><br><span class="line">import org.quartz.JobExecutionContext;</span><br><span class="line">import org.quartz.JobExecutionException;</span><br><span class="line">import org.slf4j.Logger;</span><br><span class="line">import org.slf4j.LoggerFactory;</span><br><span class="line">import org.springframework.scheduling.quartz.QuartzJobBean;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 商品秒杀提醒定时器</span><br><span class="line"> * 为关注该秒杀商品的用户进行推送提醒</span><br><span class="line"> * ========================</span><br><span class="line"> *</span><br><span class="line"> * @author 恒宇少年</span><br><span class="line"> * Created with IntelliJ IDEA.</span><br><span class="line"> * Date：2017/11/12</span><br><span class="line"> * Time：9:23</span><br><span class="line"> * 码云：http://git.oschina.net/jnyqy</span><br><span class="line"> * ========================</span><br><span class="line"> */</span><br><span class="line">public class GoodSecKillRemindTimer</span><br><span class="line">extends QuartzJobBean</span><br><span class="line">&#123;</span><br><span class="line">    /**</span><br><span class="line">     * logback</span><br><span class="line">     */</span><br><span class="line">    private Logger logger = LoggerFactory.getLogger(GoodSecKillRemindTimer.class);</span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 任务指定逻辑</span><br><span class="line">     * @param jobExecutionContext</span><br><span class="line">     * @throws JobExecutionException</span><br><span class="line">     */</span><br><span class="line">    @Override</span><br><span class="line">    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException &#123;</span><br><span class="line">        //获取任务详情内的数据集合</span><br><span class="line">        JobDataMap dataMap = jobExecutionContext.getJobDetail().getJobDataMap();</span><br><span class="line">        //获取商品编号</span><br><span class="line">        Long goodId = dataMap.getLong(&quot;goodId&quot;);</span><br><span class="line">        </span><br><span class="line">        logger.info(&quot;分布式节点quartz-cluster-node-first，开始处理秒杀商品：&#123;&#125;，关注用户推送消息.&quot;,goodId);</span><br><span class="line"></span><br><span class="line">        //.../</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>在秒杀提醒任务逻辑中，我们通过获取<code>JobDetail</code>的<code>JobDataMap</code>集合来获取在创建任务的时候传递的参数集合，我们这里约定了<code>goodId</code>为商品的编号，在创建任务的时候传递到<code>JobDataMap</code>内，这样<code>quartz</code>在执行该任务的时候就会自动将参数传递到任务逻辑中，我们也就可以通过<code>JobDataMap</code>获取到对应的参数值。</p>
<p>####设置秒杀提醒任务</p>
<p>我们找到节点项目<code>quartz-cluster-node-first</code>中的<code>GoodInfoService</code>，编写方法<code>buildGoodSecKillRemindTimer</code>设置秒杀提醒任务，如下所示：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line">     * 构建商品秒杀提醒定时任务</span><br><span class="line">     * 设置五分钟后执行</span><br><span class="line">     * @throws Exception</span><br><span class="line">     */</span><br><span class="line">    public void buildGoodSecKillRemindTimer(Long goodId) throws Exception</span><br><span class="line">    &#123;</span><br><span class="line">        //任务名称</span><br><span class="line">        String name = UUID.randomUUID().toString();</span><br><span class="line">        //任务所属分组</span><br><span class="line">        String group = GoodSecKillRemindTimer.class.getName();</span><br><span class="line">        //秒杀开始时间</span><br><span class="line">        long startTime = System.currentTimeMillis() + 1000 * 5 * 60;</span><br><span class="line">        JobDetail jobDetail = JobBuilder</span><br><span class="line">                .newJob(GoodSecKillRemindTimer.class)</span><br><span class="line">                .withIdentity(name,group)</span><br><span class="line">                .build();</span><br><span class="line"></span><br><span class="line">        //设置任务传递商品编号参数</span><br><span class="line">        jobDetail.getJobDataMap().put(&quot;goodId&quot;,goodId);</span><br><span class="line"></span><br><span class="line">        //创建任务触发器</span><br><span class="line">        Trigger trigger = TriggerBuilder.newTrigger().withIdentity(name,group).startAt(new Date(startTime)).build();</span><br><span class="line">        //将触发器与任务绑定到调度器内</span><br><span class="line">        scheduler.scheduleJob(jobDetail,trigger);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<p>我们模拟秒杀提醒时间是添加商品后的5分钟，我们通过调用<code>jobDetail</code>实例的<code>getJobDataMap</code>方法就可以获取该任务数据集合，直接调用<code>put</code>方法就可以进行设置指定key的值，该集合继承了<code>StringKeyDirtyFlagMap</code>并且实现了<code>Serializable</code>序列化，因为需要将数据序列化到数据库的<code>qrtz_job_details</code>表内。<br>修改保存商品方法，添加调用秒杀提醒任务：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 保存商品基本信息</span><br><span class="line"> * @param good 商品实例</span><br><span class="line"> * @return</span><br><span class="line"> */</span><br><span class="line">public Long saveGood(GoodInfoEntity good) throws Exception</span><br><span class="line">&#123;</span><br><span class="line">    goodInfoRepository.save(good);</span><br><span class="line">    //构建创建商品定时任务</span><br><span class="line">    buildCreateGoodTimer();</span><br><span class="line">    //构建商品库存定时任务</span><br><span class="line">    buildGoodStockTimer();</span><br><span class="line">    //构建商品描述提醒定时任务</span><br><span class="line">    buildGoodSecKillRemindTimer(good.getId());</span><br><span class="line">    return good.getId();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####添加测试商品<br>下面我们调用节点<code>quartz-cluster-node-first</code>的测试<code>Chapter39ApplicationTests.addGood</code>方法完成商品的添加，由于我们的<code>quartz-cluster-node-second</code>项目并没有停止，所以我们在<code>quartz-cluster-node-second</code>项目的控制台查看输出内容：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">2017-11-12 11:45:00.008  INFO 11652 --- [ryBean_Worker-5] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:45:00 CST 2017</span><br><span class="line">2017-11-12 11:45:30.013  INFO 11652 --- [ryBean_Worker-6] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:45:30 CST 2017</span><br><span class="line">2017-11-12 11:45:48.230  INFO 11652 --- [ryBean_Worker-7] c.hengyu.chapter39.timers.GoodAddTimer   : 分布式节点quartz-cluster-node-second，商品添加完成后执行任务，任务时间：Sun Nov 12 11:45:48 CST 2017</span><br><span class="line">2017-11-12 11:46:00.008  INFO 11652 --- [ryBean_Worker-8] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:46:00 CST 2017</span><br><span class="line">2017-11-12 11:46:30.016  INFO 11652 --- [ryBean_Worker-9] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:46:30 CST 2017</span><br><span class="line">2017-11-12 11:47:00.011  INFO 11652 --- [yBean_Worker-10] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:47:00 CST 2017</span><br><span class="line">2017-11-12 11:47:30.028  INFO 11652 --- [ryBean_Worker-1] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:47:30 CST 2017</span><br><span class="line">2017-11-12 11:48:00.014  INFO 11652 --- [ryBean_Worker-2] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:48:00 CST 2017</span><br><span class="line">2017-11-12 11:48:30.013  INFO 11652 --- [ryBean_Worker-3] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:48:30 CST 2017</span><br><span class="line">2017-11-12 11:49:00.010  INFO 11652 --- [ryBean_Worker-4] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:49:00 CST 2017</span><br><span class="line">2017-11-12 11:49:30.028  INFO 11652 --- [ryBean_Worker-5] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:49:30 CST 2017</span><br><span class="line">2017-11-12 11:49:48.290  INFO 11652 --- [ryBean_Worker-6] c.h.c.timers.GoodSecKillRemindTimer      : 分布式节点quartz-cluster-node-second，开始处理秒杀商品：15，关注用户推送消息.</span><br><span class="line">2017-11-12 11:50:00.008  INFO 11652 --- [ryBean_Worker-7] c.h.c.timers.GoodStockCheckTimer         : 分布式节点quartz-cluster-node-second，执行库存检查定时任务，执行时间：Sun Nov 12 11:50:00 CST 2017</span><br></pre></td></tr></table></figure></p>
<p>秒杀任务在添加完成商品后的五分钟开始执行的，而我们也正常的输出了传递过去的<code>goodId</code>商品编号的参数，而秒杀提醒任务执行一次后也被自动释放了。</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>本章主要是结合上一章完成了分布式任务的讲解，完成了测试持久化的定时任务自动漂移，以及如何向定时任务传递参数。当然在实际的开发过程中，任务创建是需要进行封装的，目的也是为了减少一些冗余代码以及方面后期统一维护定时任务。</p>
<p>本章源码已经上传到码云：<br>SpringBoot配套源码地址：<a href="https://gitee.com/hengboy/spring-boot-chapter" target="_blank" rel="noopener">https://gitee.com/hengboy/spring-boot-chapter</a><br>SpringCloud配套源码地址：<a href="https://gitee.com/hengboy/spring-cloud-chapter" target="_blank" rel="noopener">https://gitee.com/hengboy/spring-cloud-chapter</a><br>SpringBoot相关系列文章请访问：<a href="http://www.jianshu.com/p/9a08417e4e84" target="_blank" rel="noopener">目录：SpringBoot学习目录</a><br>QueryDSL相关系列文章请访问：<a href="http://www.jianshu.com/p/99a5ec5c3bd5" target="_blank" rel="noopener">QueryDSL通用查询框架学习目录</a><br>SpringDataJPA相关系列文章请访问：<a href="http://www.jianshu.com/p/615ed9c1fe84" target="_blank" rel="noopener">目录：SpringDataJPA学习目录</a><br>SpringBoot相关文章请访问：<a href="http://www.jianshu.com/p/9a08417e4e84" target="_blank" rel="noopener">目录：SpringBoot学习目录</a>，感谢阅读！<br>欢迎加入QQ技术交流群，共同进步。<br><img src="http://upload-images.jianshu.io/upload_images/4461954-d80b777ca38632ba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="">QQ技术交流群</p>

        
        </div>
        <footer class="article-footer">
            <div class="share-container">


    <div class="bdsharebuttonbox">
    <a href="#" class="bds_more" data-cmd="more">分享到：</a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a>
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a>
    <a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博">腾讯微博</a>
    <a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网">人人网</a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a>
</div>
<script>
window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{"bdSize":16}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
</script>
<style>
    .bdshare_popup_box {
        border-radius: 4px;
        border: #e1e1e1 solid 1px;
    }
    .bdshare-button-style0-16 a,
    .bdshare-button-style0-16 .bds_more {
        padding-left: 20px;
        margin: 6px 10px 6px 0;
    }
    .bdshare_dialog_list a,
    .bdshare_popup_list a,
    .bdshare_popup_bottom a {
        font-family: 'Microsoft Yahei';
    }
    .bdshare_popup_top {
        display: none;
    }
    .bdshare_popup_bottom {
        height: auto;
        padding: 5px;
    }
</style>


</div>

            
    

        </footer>
    </div>
    
        
<nav id="article-nav">
    
        <a href="/spring-boot-chapter-41/" id="article-nav-newer" class="article-nav-link-wrap">
            <strong class="article-nav-caption">上一篇</strong>
            <div class="article-nav-title">
                
                    第四十一章： 基于SpringBoot &amp; RabbitMQ完成DirectExchange分布式消息消费
                
            </div>
        </a>
    
    
        <a href="/spring-boot-chapter-39/" id="article-nav-older" class="article-nav-link-wrap">
            <strong class="article-nav-caption">下一篇</strong>
            <div class="article-nav-title">第三十九章：基于SpringBoot &amp; Quartz完成定时任务分布式单节点持久化</div>
        </a>
    
</nav>


    
</article>


    
    

</section>
            
			
				
<aside id="sidebar">
   
        
    <div class="widget-wrap">
        <h3 class="widget-title">最新文章</h3>
        <div class="widget">
            <ul id="recent-post" class="no-thumbnail">
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-52/" class="title">第五十二章：基于SpringBoot2使用Rest访问MongoDB数据</a></p>
                            <p class="item-date"><time datetime="2018-04-21T16:00:00.000Z" itemprop="datePublished">2018-04-22</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-51/" class="title">第五十一章：基于SpringBoot2 &amp; MongoDB完成自动化集成</a></p>
                            <p class="item-date"><time datetime="2018-04-15T16:00:00.000Z" itemprop="datePublished">2018-04-16</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-50/" class="title">第五十章：SpringBoot2.0新特性 - 岂止至今最简单redis缓存集成</a></p>
                            <p class="item-date"><time datetime="2018-04-14T16:00:00.000Z" itemprop="datePublished">2018-04-15</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-49/" class="title">第四十九章：SpringBoot2.0新特性 - 你get到WebMvcConfigurer两种配置方式了吗？</a></p>
                            <p class="item-date"><time datetime="2018-03-16T16:00:00.000Z" itemprop="datePublished">2018-03-17</time></p>
                        </div>
                    </li>
                
                    <li>
                        
                        <div class="item-inner">
                            <p class="item-category"><a class="article-category-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a></p>
                            <p class="item-title"><a href="/spring-boot-chapter-48/" class="title">第四十八章：SpringBoot2.0新特性 - RabbitMQ信任package设置</a></p>
                            <p class="item-date"><time datetime="2018-03-12T16:00:00.000Z" itemprop="datePublished">2018-03-13</time></p>
                        </div>
                    </li>
                
            </ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">分类</h3>
        <div class="widget">
            <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/QueryDSL-核心技术/">QueryDSL 核心技术</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/SpringBoot-核心技术/">SpringBoot 核心技术</a><span class="category-list-count">36</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">归档</h3>
        <div class="widget">
            <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/04/">四月 2018</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/03/">三月 2018</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/01/">一月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/12/">十二月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/11/">十一月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/10/">十月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/09/">九月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/08/">八月 2017</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/07/">七月 2017</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/06/">六月 2017</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/04/">四月 2017</a><span class="archive-list-count">5</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签</h3>
        <div class="widget">
            <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/QueryDSL/">QueryDSL</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SpringBoot/">SpringBoot</a><span class="tag-list-count">43</span></li></ul>
        </div>
    </div>

    
        
    <div class="widget-wrap">
        <h3 class="widget-title">标签云</h3>
        <div class="widget tagcloud">
            <a href="/tags/QueryDSL/" style="font-size: 10px;">QueryDSL</a> <a href="/tags/SpringBoot/" style="font-size: 20px;">SpringBoot</a>
        </div>
    </div>

    
        
    <div class="widget-wrap widget-list">
        <h3 class="widget-title">链接</h3>
        <div class="widget">
            <ul>
                
                    <li>
     				<a href="http://hexo.io" target="_blank">Hexo</a>
					</li>
                
            </ul>
        </div>
    </div>


    
    <div id="toTop" class="fa fa-angle-up"></div>
</aside>

				
        </div>
        <!--引入不蒜子-->
<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<footer id="footer">
    <div class="outer">
        <div id="footer-info" class="inner">
            <span  id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
            &copy; 2017 - 2018 恒宇少年 - 版权所有<br>
        </div>
    </div>
</footer>

        


    
        <script src="/libs/lightgallery/js/lightgallery.min.js"></script>
        <script src="/libs/lightgallery/js/lg-thumbnail.min.js"></script>
        <script src="/libs/lightgallery/js/lg-pager.min.js"></script>
        <script src="/libs/lightgallery/js/lg-autoplay.min.js"></script>
        <script src="/libs/lightgallery/js/lg-fullscreen.min.js"></script>
        <script src="/libs/lightgallery/js/lg-zoom.min.js"></script>
        <script src="/libs/lightgallery/js/lg-hash.min.js"></script>
        <script src="/libs/lightgallery/js/lg-share.min.js"></script>
        <script src="/libs/lightgallery/js/lg-video.min.js"></script>
    
    
        <script src="/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>
    
    



<!-- Custom Scripts -->
<script src="/js/main.js"></script>

    </div>
</body>
</html>